package com.zk.service.impl;

import com.zk.dao.AdminDao;
import com.zk.dao.UserDao;
import com.zk.model.Admin;
import com.zk.model.Goods;
import com.zk.model.Order;
import com.zk.model.User;
import com.zk.service.AdminService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;


@Service
public class AdminServiceImpl implements AdminService {
    @Resource
    private AdminDao adminDao;
    @Resource
    private UserDao userDao;
//    管理员登录
    @Override
    public Admin selectAdmin(String adminName, String adminPsd) {
        Admin admin=adminDao.selectAdmin(adminName,adminPsd);
        return admin;
    }
//    商品查看
    @Override
    public List<Goods> selectGoods() {
        List<Goods> goodsList=adminDao.selectGoods();
        return goodsList;
    }
//订单查看
    @Override
    public List<Order> selectOrders() {
        List<Order> orderList=adminDao.selectOrders();
        for(Order order:orderList){
            Goods goods=userDao.selectGoods(order.getOrderGoodId());
            order.setName(goods.getName());
            order.setImg(goods.getImg());
            order.setSize(goods.getSize());
            User user=adminDao.selectUserById(order.getOrderUserId());
            order.setUserName(user.getName());
            order.setUserAdress(user.getAdress());
            order.setUserPhone(user.getPhone());
        }
        return orderList;
    }
//获取商品
    @Override
    public User selectUserById(Integer id) {
        User user=adminDao.selectUserById(id);
        return user;
    }
//添加商品
    @Override
    public int addGood(String name, Integer price, String img, Integer stock, String size) {
        int num=adminDao.addGoods(name,price,img,stock,size);
        return num;
    }
//添加快递
    @Override
    public int addState(String orderState, String trackingNumber, String trackingName,Integer orderId) {
        int num=adminDao.addState(orderState,trackingNumber,trackingName,orderId);
        return num;
    }
}
